package APong.Entity;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.state.StateBasedGame;

import APong.World.World;

public class Paddle extends Entity {

	
	protected boolean isPlayer;
	protected boolean isUsingKeyboard = true;
	public Paddle(World world, float x, float y) {
		super(world, x, y,20,100);
		
	}

	@Override
	protected void renderEntity(GameContainer gc, Graphics g) {
		this.fillCollisionShape(g);
		
	}

	@Override
	protected void updateEntity(GameContainer gc, StateBasedGame sbg) {
		if(isPlayer){
			Input input = gc.getInput();
			if(isUsingKeyboard){
			if(input.isKeyDown(Input.KEY_W)){this.setYVel(-1);}
			if(input.isKeyDown(Input.KEY_S)){this.setYVel(1);}
			}else{
				float xt = input.getMouseX();
				float yt = input.getMouseY();
				moveTo(x,yt - height / 2,1f);
			}
		}else{
			Entity entity = null;
			for(Entity en: world.entities){
						entity = en;
				
				if(entity instanceof Ball){
					moveTo(0,entity.getXPos(), 1f);
					break;
				}
			}
			
		}
		
	}

	@Override
	public Shape getCollisionShape(float xa, float ya) {
		return new Rectangle((x + (world.getDeltaTime() * xa)), (y + (world.getDeltaTime() * ya)), width, height);
	}

	@Override
	public boolean isSolid(Entity e) {
		return true;
	}

	@Override
	public void collide(Entity e) {
		if(e instanceof Wall){
			this.canPass = false;
		}
		
	}
	public void setIsPlayer(boolean b){
		this.isPlayer = b;
	}
	public void setIsUsingKeyboard(boolean b){
		this.isUsingKeyboard = b;
	}
	public boolean getIsPlayer(){
		return isPlayer;
	}
	public boolean isUsingKeyboard(){
		return isUsingKeyboard;
	}

}
